package cate.game.server.service;

import cate.game.ManyGame;
import cate.game.common.rpc.RpcListener4Process;
import cate.game.framework.share.Shared;
import cate.game.server.service.process.ProcessCmds;
import cp.solution.business.game.cmd.GameBatchCmd;
import cp.solution.rpc.path.RpcSharePath;
import cp.solution.rpc.path.RpcSysPath;
import cp.solution.util.demo.vo.DemoAppleVo;
import cp.solution.util.demo.vo.DemoBananaVo;
import easy.java.struct.ref.StringRef;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class RpcService implements InitializingBean {

    @Resource
    ManyGame games;

    @Resource
    RpcListener4Process rpcListener4Process;

    @Override
    public void afterPropertiesSet() throws Exception {
        rpcListener4Process.onRequestResponseTemplate(RpcSharePath.DEV_DEBUG, DemoAppleVo.class, (head, input) -> {
            log.info("收到{} : {}", RpcSharePath.DEV_DEBUG, input);
            return DemoBananaVo.random();
        });

        rpcListener4Process.onFireAndForgetTemplate(RpcSharePath.BATCH_CMD, GameBatchCmd.class, (head, input) -> {
            Shared.logic.batchCmd(input);
        });

        rpcListener4Process.onFireAndForgetTemplate(RpcSharePath.BATCH_MAIL_NOTICE, String.class, (head, input) -> {
            Shared.logic.batchMail(input);
        });

        rpcListener4Process.onRequestResponseTemplate(RpcSysPath.GAME_JVM_INFO, StringRef.class,
                (head, input) -> ProcessCmds.jvmInfo(input));

        rpcListener4Process.onRequestResponseTemplate(RpcSysPath.GAME_JVM_GC, StringRef.class,
                (head, input) -> ProcessCmds.jvmGc(input));

        rpcListener4Process.onRequestResponseTemplate(RpcSysPath.GAME_EXCEL_RELOAD, String.class,
                (head, input) -> ProcessCmds.reloadExcel(input));
    }

}
